<?php
	require_once('../libraryfiles/config.php');
	$content = 'addprescription.php';
	$include = ' 
	<script src="'.W_ROOT.'/js/jquery-1.2.6.min.js" type="text/javascript"></script>
	<script src="'.W_ROOT.'/js/jquery-1.5.1.min.js" type="text/javascript"></script>
	<script src="'.W_ROOT.'/js/common.js" type="text/javascript"></script>	
	';    
	
	if(!empty($check_date)){
		$check_date = ",'".$check_date."'";	
	}else{
		$check_date = '';	
	}
		
	$var = '<span style="color:#F00">*</span>';
	require_once TMP_USER_PATH;
?>
<style type="text/css">
.hide{
	display: none;
}
.hidel{
	display: none;
}
</style>
<script type="text/javascript">
function checkpreform(){
	var patien_name = document.forms['frmaddpre']['patient_name'].value;
	var patien_age = document.forms['frmaddpre']['patient_age'].value;
	var patien_sex = document.forms['frmaddpre']['patient_sex'].value;
	var patien_weight = document.forms['frmaddpre']['patient_weight'].value;
	var patien_height = document.forms['frmaddpre']['patient_height'].value;	
	
	if(patien_name == ""){
		alert("Please input patient name!");	
		document.forms['frmaddpre']['patient_name'].focus();
		return false;
	} else if(patien_age == ""){
		alert("Please input patient age!");	
		document.forms['frmaddpre']['patient_age'].focus();
		return false;
	} else if(patien_sex == ""){
		alert("Please select patient sex!");	
		document.forms['frmaddpre']['patient_sex'].focus();
		return false;
	} else if(patien_weight == ""){
		alert("Please input patient weight!");	
		document.forms['frmaddpre']['patient_weight'].focus();
		return false;
	} else if(patien_height == ""){
		alert("Please input patient height!");	
		document.forms['frmaddpre']['patient_height'].focus();
		return false;
	}
	var selValid = true;
		$('.qty').each(function(){
		if($(this).val()==""){
			alert("Please input product quantity!");
			$(this).focus();
			selValid= false;
			return false;
		}
		});
		
	if(selValid == false){
			return false;
	}else{
		document.frmaddpre.submit();
	}
}

var selHtml = '';
var same_pro = '';

function deleteItem(aLink){
	 if(confirm('Delete this one!')) {
		 var tbl = aLink.parent().parent().parent().parent();
		 tbl.fadeOut('slow',function(){
			tbl.remove();
		 });
		 return false;
	 }
}
$(document).ready(function($){
	$("#btnsearch").click(function(){
			var txtpro_name = document.frmaddpre.pro_name.value;
			
			if(txtpro_name == ""){
				alert("Please input text to search!");	
				document.forms['frmaddpre']['pro_name'].focus();
				return false;
			}
			
			$('#imgLoading').removeClass('hide');
			//alert(txtpro_name);
			$.ajax({
				type: "GET",
				url: "process.php",
				data: "action=search_pro&searchword=" + txtpro_name + "&samepro=" + same_pro,
				success: function(message){
					$('#result').html(message);
					$('#result').show();
					$('#imgLoading').addClass('hide');
					
					
					$(".addproduct").click(function(){
					  var pro_id = $(this).attr("id");
					  var count_id = $(this).parent().find("input[name=count_name]").val();
					  var same_id = $(this).parent().find("input[name=hidephapid]").val();  
					  if(same_pro==""){
						same_pro = $(this).parent().find("input[name=hidephapid]").val();  
					  }else{
						  same_pro += ","+$(this).parent().find("input[name=hidephapid]").val();  
					  }
					  
/*					  var dup = 0;
					  $("#showaddproduct table").each(function(){
					  		if($(this).find("tr td:first").text() == pro_id){
								dup++;
							}
					  });
					  if(dup > 0){
						 alert("Product Already Exist!"); 
						 return false;
					  }*/
					  
					  $('#Loading').removeClass('hidel');
					  $.ajax({
						  type: "GET",
						  url: "process.php",
						  data: "action=diplayexist&id=" + pro_id +"&count_id="+ count_id + "&pid="+same_id,
						  success: function(message){
							  $('#result').hide(500);
							   $('#displayTR').show();
							   $('#submitbtn').show();
							  $('#showaddproduct').append(message);
							  $('#Loading').addClass('hidel');
						  }
					  });
				  });
				}
			});
			
		});			
		
})
</script>
<script type="text/javascript" src="calendar_us.js"></script>
<link rel="stylesheet" href="calendar.css">
<div class="row-fluid">
	<div class="box">
<form action="process.php?action=addpre" name="frmaddpre" id="frmaddpre" method="post" enctype="multipart/form-data">
<div class="title">Add Prescription</div>
<div class="center">
<p align="center" style="font-size:20px;">Prescription</p>
<div style="border-top:2px dotted #666; margin:0px 10px 0px 10px;">&nbsp;</div>
<table cellpadding="5" cellspacing="5" border="0">
<tr>
        	<td colspan="9" align="right"><span>Note: <?php echo $var; ?> are required field.</span></td>
</tr>
<tr>
<td>Patient Name<?php echo $var; ?></td><td width="5">:</td><td><input type="text" name="patient_name" style="width:90px;" /></td>
<td align="right">Age<?php echo $var; ?></td><td width="5">:</td><td><input type="text" name="patient_age" style="width:50px;" onkeyup="checkNumber(this);" /></td>
<td align="right">Sex<?php echo $var; ?></td><td width="5">:</td><td>
<select name="patient_sex" style="width:90px;">
	<option value="">---</option>
	<option value="Female">Female</option>
	<option value="Male">Male</option>    
</select>
</td>
</tr>
<tr>
<td>Weight<?php echo $var; ?></td><td width="5">:</td><td><input type="text" name="patient_weight" style="width:90px;" onkeyup="checkNumber(this);" /></td>
<td>Height<?php echo $var; ?></td><td width="5">:</td><td><input type="text" name="patient_height" style="width:50px;" onkeyup="checkNumber(this);" /></td>
<td>Doctor Name</td><td width="5">:</td><td><input type="text" name="doctor_name" style="width:90px;" /></td>
</tr>
<tr>
<td>Check Date</td><td width="5">:</td><td><input type="text" name="check_date" style="width:70px;" />
	<script language="JavaScript">
	new tcal ({
		// form name
		'formname': 'frmaddpre',
		// input name
		'controlname': 'check_date'
	});

	</script></td>
    <td></td>
<td colspan="3" align="right">Prescription Number<td width="5">:</td></td><td><input type="text" name="pre_num" style="width:90px;" /></td>    
</tr>
<tr>
<td valign="top">Note</td>
<td width="5" valign="top">:</td>
<td colspan="7">
<textarea name="txtnote" cols="52" rows="3" style="border:1px solid #033789"></textarea>
</td>
</tr>
</table>
<p align="center" style="font-size:15px;">Add Product</p>
<div style="border-top:2px dotted #666; margin:0px 10px 0px 10px;">&nbsp;</div>
<table width="99%" cellpadding="5" cellspacing="5" border="0">
<tr>
	<td>Product Name</td>
    <td width="20">:</td>
    <td><input type="text" name="pro_name" style="width:235px;" onKeyPress="return disableEnterKey(event)" />&nbsp;&nbsp;&nbsp;&nbsp;
    <input class="btn" type="button" value="Search" name="btnsearch" id="btnsearch" />
    </td> 
</tr>
<tr>
	<td></td>
    <td></td>
	<td>
    <img src="ajax-loader.gif" id="imgLoading" border="0" class="hide" />
    <div id="result"></div>
    </td>
</tr>
</table>
<br />
<a name="1"></a>
<table cellpadding="0" cellspacing="0" border="0" id="displayPro" width="100%" style="padding:0px 5px 0px 5px;">
<tr id="displayTR" style="display:none;">
<td width="30" class="col3"></td>
<td width="100" align="center" class="col3">Image</td>
<td align="center" width="250" class="col3">Product Name</td>
<td align="center" width="150" class="col3_1">Quantity</td>
</tr>
</table>
<div id="showaddproduct">

</div>
<p align="right" style="padding-right:10px; display:none;" id="submitbtn">
<strong style="color:#F00">* Please check your data again before you submit!</strong>
<br /><br />
<input class="btn" type="button" name="btnsubmit" value="Submit" onclick="checkpreform();" />
</p>
<img src="ajax-loader.gif" id="Loading" border="0" class="hidel" />
</div>
</form>
	</div><!--<div class="box">-->
</div><!--<div class="row-fluid">-->